with Ada.Strings.Bounded;

--
-- test Headers Parser package
--

package body Test_Headers_Parser

is

   --
   -- run all tests
   --

   procedure Tests_Suite
   is

   begin

      Test_Parse_Headers;

      Test_Parse_Content;

      Test_Parse_Headers_Get_Content_Length;

   end Tests_Suite;


   --
   -- test function which retrieves headers only
   --

   procedure Test_Parse_Headers is separate;


   --
   -- test find numeric content-length header value
   --

   procedure Test_Parse_Headers_Get_Content_Length is separate;


   --
   -- test function which retrieves content only
   --

   procedure Test_Parse_Content is separate;


   --
   -- read HTTP test data for use as test input
   --

   function Read_Test_Data_File return String
   is

      package HTTP_String_Data_Type is new Ada.Strings
            .Bounded
            .Generic_Bounded_Length( Max => MAX_HTTP_DATA_LENGTH );

      HTTP_String_Data : HTTP_String_Data_Type.Bounded_String;

   begin

      HTTP_String_Data_Type.Delete( HTTP_String_Data,
            1,
            HTTP_String_Data_Type.Length( HTTP_String_Data ));

      Text_IO.Open( File => Test_File_In,
                    Mode => Text_IO.In_File,
                    Name => TEST_WEB_DATA_FILE );

      while not Text_IO.End_Of_File( Test_File_In ) loop

         declare

            Buffer : constant String := Text_IO.Get_Line(

              File => Test_File_In )

              & Ascii.LF;

         begin

            HTTP_String_Data_Type.Append( HTTP_String_Data, Buffer );

         end;

      end loop;

      Text_IO.Close( Test_File_In );

      if( HTTP_String_Data_Type.Length(HTTP_String_Data) < 1 ) then

         raise Test_File_Empty;

      end if;

      return HTTP_String_Data_Type.To_String( HTTP_String_Data );

   end Read_Test_Data_File;


end Test_Headers_Parser;